import db from './db'
import { mock } from 'mockjs'
// 排序
import { orderBy } from '@/utils'

mock('carousel/list', 'get', () => {
  return {
    err: 0,
    desc: '执行成功！',
    result: orderBy(db.select('gx_carousel'))
  }
})
// POST轮播状态,
mock('carousel/state', 'post', (payload) => {
  const { id, state } = JSON.parse(payload.body)
  return {
    err: 0,
    desc: '执行成功！',
    // 修改数据库内容
    result: db.put('gx_carousel', id, { state })
  }
})
// POST轮播删除
mock('carousel/remove', 'post', (payload) => {
  const { ids } = JSON.parse(payload.body)
  return {
    err: 0,
    desc: '执行成功！',
    // 删除数据库内容
    result: db.delete('gx_carousel', ids)
  }
})

// POST轮播增加
mock('carousel/add', 'post', (payload) => {
  const form = JSON.parse(payload.body)
  return {
    err: 0,
    desc: '执行成功！',
    result: db.add('gx_carousel', form)
  }
})

// POST轮播修改
mock('carousel/edit', 'post', (payload) => {
  const { id, ...others } = JSON.parse(payload.body)
  return {
    err: 0,
    desc: '执行成功！',
    // 修改数据库内容
    result: db.put('gx_carousel', id, others)
  }
})
